package com.xrf;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ProjectBasicInfo {
    private String projectNumber;
    private String projectName;
    private String projectCategory;
    private String projectTime;
    private Double branchOrDepartment;
    private Long salesPersonInCharge;
    private Long mainResponsibilityDeliveryDepartment;
    private String projectManager;

    private static List<ProjectBasicInfo> list = new ArrayList<>();
    private static Scanner scanner = new Scanner(System.in);

    public ProjectBasicInfo() {}

    public ProjectBasicInfo(String projectNumber, String projectName, String projectCategory,
                           String projectTime, Double branchOrDepartment, Long salesPersonInCharge,
                           Long mainResponsibilityDeliveryDepartment, String projectManager) {
        this.projectNumber = projectNumber;
        this.projectName = projectName;
        this.projectCategory = projectCategory;
        this.projectTime = projectTime;
        this.branchOrDepartment = branchOrDepartment;
        this.salesPersonInCharge = salesPersonInCharge;
        this.mainResponsibilityDeliveryDepartment = mainResponsibilityDeliveryDepartment;
        this.projectManager = projectManager;
    }

    // Getter and Setter methods
    public String getProjectNumber() { return projectNumber; }
    public void setProjectNumber(String projectNumber) { this.projectNumber = projectNumber; }
    public String getProjectName() { return projectName; }
    public void setProjectName(String projectName) { this.projectName = projectName; }
    public String getProjectCategory() { return projectCategory; }
    public void setProjectCategory(String projectCategory) { this.projectCategory = projectCategory; }
    public String getProjectTime() { return projectTime; }
    public void setProjectTime(String projectTime) { this.projectTime = projectTime; }
    public Double getBranchOrDepartment() { return branchOrDepartment; }
    public void setBranchOrDepartment(Double branchOrDepartment) { this.branchOrDepartment = branchOrDepartment; }
    public Long getSalesPersonInCharge() { return salesPersonInCharge; }
    public void setSalesPersonInCharge(Long salesPersonInCharge) { this.salesPersonInCharge = salesPersonInCharge; }
    public Long getMainResponsibilityDeliveryDepartment() { return mainResponsibilityDeliveryDepartment; }
    public void setMainResponsibilityDeliveryDepartment(Long mainResponsibilityDeliveryDepartment) { this.mainResponsibilityDeliveryDepartment = mainResponsibilityDeliveryDepartment; }
    public String getProjectManager() { return projectManager; }
    public void setProjectManager(String projectManager) { this.projectManager = projectManager; }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("项目编号:").append(projectNumber).append("\t");
        builder.append("项目名称:").append(projectName).append("\t");
        builder.append("项目类别:").append(projectCategory).append("\t");
        builder.append("立项时间:").append(projectTime).append("\t");
        builder.append("分公司或部门:").append(branchOrDepartment).append("\t");
        builder.append("销售负责人:").append(salesPersonInCharge).append("\t");
        builder.append("主责交付部门:").append(mainResponsibilityDeliveryDepartment).append("\t");
        builder.append("项目经理:").append(projectManager).append("\t");
        return builder.toString();
    }

    public static void addData() {
        System.out.println("--------添加数据-------");
        System.out.println("请输入项目编号：");
        String projectNumber = scanner.next();
        System.out.println("请输入项目名称：");
        String projectName = scanner.next();
        System.out.println("请输入项目类别：");
        String projectCategory = scanner.next();
        System.out.println("请输入立项时间：");
        String projectTime = scanner.next();
        System.out.println("请输入分公司或部门：");
        Double branchOrDepartment = scanner.nextDouble();
        System.out.println("请输入销售负责人：");
        Long salesPersonInCharge = scanner.nextLong();
        System.out.println("请输入主责交付部门：");
        Long mainResponsibilityDeliveryDepartment = scanner.nextLong();
        System.out.println("请输入项目经理：");
        String projectManager = scanner.next();
        
        ProjectBasicInfo data = new ProjectBasicInfo(projectNumber, projectName, projectCategory,
                                                   projectTime, branchOrDepartment, salesPersonInCharge,
                                                   mainResponsibilityDeliveryDepartment, projectManager);
        list.add(data);
    }

    public static void removeData() {
        System.out.println("--------删除数据-------");
        System.out.println("请输入索引：");
        int index = scanner.nextInt();
        if (index >= 0 && index < list.size()) {
            list.remove(index);
            System.out.println("删除成功！");
        } else {
            System.out.println("索引无效！");
        }
    }

    public static void updateData() {
        System.out.println("--------修改数据-------");
        System.out.println("请输入索引：");
        int index = scanner.nextInt();
        if (index >= 0 && index < list.size()) {
            System.out.println("请输入项目编号：");
            String projectNumber = scanner.next();
            System.out.println("请输入项目名称：");
            String projectName = scanner.next();
            System.out.println("请输入项目类别：");
            String projectCategory = scanner.next();
            System.out.println("请输入立项时间：");
            String projectTime = scanner.next();
            System.out.println("请输入分公司或部门：");
            Double branchOrDepartment = scanner.nextDouble();
            System.out.println("请输入销售负责人：");
            Long salesPersonInCharge = scanner.nextLong();
            System.out.println("请输入主责交付部门：");
            Long mainResponsibilityDeliveryDepartment = scanner.nextLong();
            System.out.println("请输入项目经理：");
            String projectManager = scanner.next();
            
            ProjectBasicInfo data = new ProjectBasicInfo(projectNumber, projectName, projectCategory,
                                                       projectTime, branchOrDepartment, salesPersonInCharge,
                                                       mainResponsibilityDeliveryDepartment, projectManager);
            list.set(index, data);
            System.out.println("修改成功！");
        } else {
            System.out.println("索引无效！");
        }
    }

    public static void displayData() {
        System.out.println("--------数据显示-------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println("索引 " + i + ": " + list.get(i));
        }
    }
}